﻿namespace PugLib.UI
{
	using System;

	using PugLib.Extensions;

	public abstract class TaskPresenter
	{
		private readonly TaskForm _view;

		protected TaskPresenter(TaskForm view)
		{
			if (view == null)
			{
				throw new ArgumentNullException("view");
			}
			_view = view;
		}

		public void StartTask<TResult>(Func<TResult> task, Action<TResult> taskContinuation)
		{
			StartTask(task, taskContinuation, TaskForm.HandleZeroExceptions);
		}

		public void StartTask<TResult>(Func<TResult> task, Action<TResult> taskContinuation, Func<Exception, Boolean> exceptionHandler)
		{
			task.StartTaskWithUIResult(exceptionHandler, taskContinuation, _view.UIScheduler);
		}
	}
}